package com.tangzhe.demo02.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * aop记录日志
 */
//@Component
//@Aspect
public class Logger {

//    @Pointcut(value = "execution(* com.tangzhe.demo02.service.*.*(..))")
//    public void pointCut() {
//
//    }
//
//    @Before(value = "pointCut()")
//    public void doBefore(JoinPoint joinpoint) {
//        String name = joinpoint.getSignature().getName();
//        Object[] args = joinpoint.getArgs();
//        System.out.println(name + ", " + args.toString());
//    }
//
//    @After(value = "pointCut()")
//    public void doAfter(JoinPoint joinPoint) {
//        String name = joinPoint.getSignature().getName();
//        System.out.println(name);
//    }
//
//    @Around(value = "pointCut()")
    public void doLog(ProceedingJoinPoint proceedingJoinPoint) {
        try {
            System.out.println("环绕前");
            proceedingJoinPoint.proceed();
            System.out.println("环绕后");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

}
